package com.test.controller.messageResource;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.MessageSource;
import org.springframework.context.support.MessageSourceAccessor;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import java.util.Locale;

/**
 * 创建人： HBZ，时间： 2017/9/2 11:24.
 * 说明：
 */
@Controller
@RequestMapping("/messageAccessor")
public class MessageSourceAccessorController {
    @Autowired
     private MessageSourceAccessor messages;;

    private String domain="message";
    @RequestMapping(value = "/hello", method = RequestMethod.GET)
    public ModelAndView index(HttpServletRequest request, ModelMap model, Locale locale) {

        System.out.println(messages.getMessage("msg.name"));
        System.out.println(messages.getMessage("msg.name",Locale.getDefault()));
        System.out.println(messages.getMessage("msg.name",locale));
//        System.out.println(messages.getMessage("msg.name",new Locale("zh","CN")));
//        System.out.println(messages.getMessage("msg.name",new Locale("en","US")));
        return new ModelAndView(domain+"/hello");

    }
}
